<!DOCTYPE html>  
<html lang="zh-CN">  
    <head>  
        <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <title>打包工具</title>
	    <link rel="stylesheet" href="style/bootstrap.css">
	    <link rel="stylesheet" href="style/main.css">
    <script type='text/javascript' src='style/jquery-2.2.1.min.js'></script>
    <script type='text/javascript' src='style/main.js'></script>
    <script type='text/javascript' src='style/localetype.js'></script>
    </head>  
  
    <body>  

    <div id="loading" style=" display: none;filter:alpha(Opacity=80);-moz-opacity:0.5;opacity: 0.5; position: fixed; width: 100%; height: 100%; background-color: rgb(171, 162, 162); z-index: 9999;margin: 0;text-align: center;font-size: 30;"><span class="h1" >运行中，请稍后。。。。 请不要关闭浏览器</span></div>

    <div id="loading-config" style=" display: none;filter:alpha(Opacity=80);-moz-opacity:0.5;opacity: 0.5; position: fixed; width: 100%; height: 100%; background-color: rgb(171, 162, 162); z-index: 9999;margin: 0;text-align: center;font-size: 30;"><span class="h1" id = readconfig-progress >正在读取配置文件....</span></div>

        <div class="panel-group">  
            <div class="panel panel-primary">  
                <div class="panel-heading">  
                   	一键打包工具(确认参数无误后一键打包)  

                    <a href="javascript:void(0)"  class="btn btn-primary"  id="excelTosqlite">GOGO</a>
                </div>  
                 
                <table class="table table-bordered table-hover">  
                    <thead>  
                        <tr class="success">  
                            <th>bundleid</th>  
                            <th>appname</th>  
                            <th>appversion</th>  
                            <th>svn tag</th>  
                            <th>icon</th>  
                            <th>baseapp</th>  
                            <th>platform</th>
                            <th>configname</th>
                        </tr>  
                    </thead>  
                    <tbody id = tableall>  
                         
                    </tbody>  
                </table>  
            </div>
        </div>  
        
        <script>  
        $(function(){  
        	function initTableCheckbox() {  
                var $thr = $('table thead tr');  
                var $checkAllTh = $('<th><input type="checkbox" id="checkAll" name="checkAll" /></th>');  
                /*将全选/反选复选框添加到表头最前，即增加一列*/  
                // $thr.prepend($checkAllTh);  
                /*“全选/反选”复选框*/  
                var $checkAll = $thr.find('input');  
                $checkAll.click(function(event){  
                    /*将所有行的选中状态设成全选框的选中状态*/  
                    $tbr.find('input').prop('checked',$(this).prop('danger'));  
                    /*并调整所有选中行的CSS样式*/  
                    if ($(this).prop('checked')) {  
                        $tbr.find('input').parent().parent().addClass('danger');  
                    } else{  
                        $tbr.find('input').parent().parent().removeClass('danger');  
                    }  
                    /*阻止向上冒泡，以防再次触发点击操作*/  
                    event.stopPropagation();  
                });  
                /*点击全选框所在单元格时也触发全选框的点击操作*/  
                $checkAllTh.click(function(){  
                    $(this).find('input').click();  
                });  
                var $tbr = $('table tbody tr');  
                var $checkItemTd = $('<td><input type="checkbox" name="checkItem" /></td>');  
                /*每一行都在最前面插入一个选中复选框的单元格*/  
                $tbr.prepend($checkItemTd);  
                /*点击每一行的选中复选框时*/  
                $tbr.find('input').click(function(event){  
                    /*调整选中行的CSS样式*/  
                    $(this).parent().parent().toggleClass('danger');  
                    /*如果已经被选中行的行数等于表格的数据行数，将全选框设为选中状态，否则设为未选中状态*/  
                    $checkAll.prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);  
                    /*阻止向上冒泡，以防再次触发点击操作*/  
                    event.stopPropagation();  
                });  
                /*点击每一行时也触发该行的选中操作*/  
                $tbr.click(function(){  
                    $(this).find('input').click();  
                });  
            }

            $("#loading-config ").show();

            $.ajax({
		        method: "GET",
		        url: "cgi-bin/pack.py",
		        data: "actiontype=getAllConfigDetail",
		        success: function(data){
		          var confNames = data.split("#");
                  var confignum = 0
                  for (var index in confNames){

                     data = JSON.parse(confNames[index].split("$")[1]);
                     var $celltable = $('<tr>  <td>'+ data["bundleid"]+'</td>  <td>'+data["appname"]+'</td>  <td>'+data["appversion"]+'</td>  <td>'+data["svn_tag"]+'</td>  <td>'+data["icon"]+'</td>  <td>'+data["baseapp"]+'</td>  <td>'+ confNames[confignum].split("$")[0] +'</td> </tr>');  
                      $('#tableall').prepend($celltable);
                      confignum = confignum + 1;
                      if(confignum == confNames.length)
                      {     
                          $("#loading-config ").hide();
                          initTableCheckbox();  
                      }
                  }
		        },
		        error:function(){
		          alert( "get All conf fail" );
		        }
		      });


            $("#excelTosqlite").click(function(){ 
                //获取选中状态
                var selectItems = ""
                var trList = $("#tableall").children("tr")
                  for (var i=0;i<trList.length;i++) {
                    var tdArr = trList.eq(i).find("td");
                    var checkbox = tdArr.eq(0).find("input");//收入类别
                    var configname = tdArr.eq(7).text();//收入类别

                    if (checkbox.is(":checked"))
                    {   
                        selectItems = selectItems + configname + ",";
                    }
                    
                  }
                if (selectItems == "" )
                {
                    alert("请选择要打包的apk or ipa")
                    return
                }  

                selectItems = selectItems.substring(0,selectItems.length -1)

                alert(selectItems)

                dev = "dis"
                recivers_email= 'gusitong@kaixin-inc.com,xuyuzhao@kaixin-inc.com,wudengku@kaixin-inc.com,zhengshiyu@kaixin-inc.com'

                $("#loading").show()
                  $.ajax({
                    method : "GET",
                    url: "cgi-bin/pack.py",
                    data: "actiontype=generateAllApp&appname="+selectItems+"&dev="+dev+"&recivers_email="+recivers_email,
                    success: function(data){
                      $("#loading").hide();
                      alert("打包完成");
                      // console.log(data);
                      Notification.requestPermission(function(status){
                         var n = new Notification("generateApp",{body:"finish"})
                      });
                    },
                    error:function(){
                      alert( "generateApp fail" );
                      $("#loading").hide();
                      Notification.requestPermission(function(status){
                        var n = new Notification("generateApp",{body:"fail"})
                      });
                    }
                  });
            });

        });  
        </script>  
    </body>  
  
</html>  